package com.bank.GOME_M27A;

import android.content.Context;
import android.support.test.InstrumentationRegistry;
import android.support.test.uiautomator.UiDevice;
import android.support.test.uiautomator.UiObject;
import android.support.test.uiautomator.UiObjectNotFoundException;
import android.support.test.uiautomator.UiSelector;
import android.text.TextUtils;
import android.util.Log;

import com.bank.Bank;
import com.entity.User;
import com.utils.ChatClient;
import com.utils.CodeUtils;
import com.utils.Constants;
import com.utils.FileHelper;
import com.utils.ImageView;
import com.utils.LogToFile;
import com.utils.PinYinUtil;

import java.text.DecimalFormat;
import java.util.ArrayList;
import java.util.List;

import static android.os.SystemClock.sleep;
import static com.bank.Bank.BANK_FLAG;
import static com.bank.Bank.BANK_NAME;
import static com.bank.Bank.ratio;
import static com.bank.Bank.sumMoney;
import static com.utils.ChatClient.CCBMethodName;
import static com.utils.ChatClient.CODE_S;
import static com.utils.ChatClient.CODE_TIMER;
import static com.utils.ChatClient.C_updateBalance_W;
import static com.utils.ChatClient.ConfirmOrder;
import static com.utils.ChatClient.PAUSE;
import static com.utils.ChatClient.RUNING;
import static com.utils.ChatClient.S_paused_C;
import static com.utils.ChatClient.addWorkTime;
import static com.utils.ChatClient.list;
import static com.utils.ChatClient.setDevicesLog;
import static com.utils.ChatClient.userInfo;
import static com.utils.Constants.isReport;
import static com.utils.Constants.notReport;
import static com.utils.Constants.orderBankName;

/**
 * 项目名称：yzf_jiao
 * 类描述：国美建行脚本
 * 创建人：Administrator
 * 创建时间：2020/5/22 11:38
 * 修改人：Administrator
 * 修改时间：2020/5/22 11:38
 * 修改备注：
 */
public class M27CCBbank {
    private int[][] xy_num = new int[][]{
            {187, 1510}, {555, 1510}, {905, 1510},
            {187, 1660}, {555, 1660}, {905, 1660},
            {187, 1820}, {555, 1820}, {905, 1820},
            {187, 1970}, {555, 1970}};
    private int[][] xy_abc = new int[][]{
            {65, 1510}, {170, 1510}, {275, 1510}, {385, 1510}, {490, 1510}, {600, 1510}, {710, 1510}, {815, 1510}, {915, 1510}, {1025, 1510},
            {65, 1670}, {170, 1670}, {275, 1670}, {385, 1670}, {490, 1670}, {600, 1670}, {710, 1670}, {815, 1670}, {915, 1670}, {1025, 1670},
            {170, 1820}, {275, 1820}, {385, 1820}, {490, 1820}, {600, 1820}, {710, 1820}, {815, 1820}, {915, 1820}, {1025, 1820},
            {220, 1970}, {330, 1970}, {440, 1970}, {545, 1970}, {655, 1970}, {760, 1970}, {870, 1970}};
    //验证码键盘，讯飞数字键盘，默认2016尺寸
    private int[][] xy_num_xunfei = new int[][]{
            {295, 1450}, {545, 1450}, {787, 1450},
            {295, 1600}, {545, 1600}, {787, 1600},
            {295, 1780}, {545, 1780}, {787, 1780},
            {545, 1960}};

    private Bank bank;
    private UiDevice mDevice;

    //    Context context = InstrumentationRegistry.getTargetContext();
    User user;
    private String type = "abc";
    private boolean isCode = false;//用来判断是否输入过图片附加码
    private int SMS_num = 0;

    public M27CCBbank(Bank bank) throws UiObjectNotFoundException {
        this.bank = bank;
        this.mDevice = bank.mDevice;
        initInfo();
    }

    private void initInfo() throws UiObjectNotFoundException {
        //检查usb连接状态
        ChatClient.begintime = System.currentTimeMillis();//开始时间
        while (true) {
            boolean isOutTime = CodeUtils.outTime(ChatClient.begintime, ChatClient.overtime_10, "检测弹窗广告结束...", notReport);
            if (isOutTime) {
                transfer();
                break;
            }
            if (Constants.STATE_USB) {
                UiObject updateDialog = mDevice.findObject(new UiSelector().resourceId("com.chinamworld.main:id/iv_close"));
                if (updateDialog.exists()) {
                    showMsg("======检测到更新弹窗，点击关闭按钮=====");
                    updateDialog.click();
                }
                sleep(ChatClient.overtime_1);
                UiObject tip = mDevice.findObject(new UiSelector().resourceId("com.chinamworld.main:id/tip_view_pager"));
                UiObject close = mDevice.findObject(new UiSelector().resourceId("com.chinamworld.main:id/close"));
                if (tip.exists()) {
                    showMsg("======检测到viewpager;点击关闭按钮1=====");
                    close.click();
                } else if (close.exists()) {
                    showMsg("======检测到关闭按钮;点击关闭按钮2=====");
                    close.click();
                }
            }
        }
    }

    //检索转账：进入转账
    public void transfer() throws UiObjectNotFoundException {
        //点击进入转账
        ChatClient.begintime = System.currentTimeMillis();//开始时间
        while (true) {
            boolean isOutTime = CodeUtils.outTime(ChatClient.begintime, ChatClient.overtime_8, "点击转账结束...", notReport);
            if (isOutTime) {
                break;
            }
            UiObject allow = mDevice.findObject(new UiSelector().text("允许").resourceId("com.android" +
                    ".packageinstaller:id/permission_allow_button"));
            if (allow.exists()) {
                //进入转账
                showMsg("点击A-MOB正在尝试读取帐号信息对话框的允许");
                allow.click();
            }
            //首页转账ID
            UiObject transfer = mDevice.findObject(new UiSelector().resourceId("com.chinamworld.main:id/main_home_smart_transfer"));
            if (transfer.exists()) {
                transfer.click();
                break;
            }
            sleep(ChatClient.overtime_1);
        }
        //获取页面上登录节点
        while (true) {
            //获取账号信息
            ChatClient.start();
            while (true) {
                if (userInfo.equals("")) {
                    ChatClient.msg("<YZF>{'header':'" + ChatClient.M_GET_BANK_LOGIN_INFO_P + "'}</YZF>");
                    sleep(ChatClient.overtime_5);
                } else {
                    user = new User();
                    String[] res = userInfo.split(" ");
                    for (int i = 0; i < res.length; i++) {
                        switch (i) {
                            case 0:
                                user.setUserName(res[0]);
                                break;
                            case 1:
                                user.setPwd(res[1]);
                                break;
                            case 2:
                                user.setBankpwd(res[2]);
                                break;
                            case 3:
                                user.setUsbPayPwd(res[3]);
                                break;
                            case 4:
                                user.setUseType(res[4]);
                                break;
                            case 5:
                                user.setBankId(res[5]);
                                break;
                        }
                    }
                    break;
                }
            }
            Login();
            break;
        }
    }

    //进入登录页面补充用户信息
    public void Login() {
        try {
            CCBMethodName = "Login";
            sleep(ChatClient.overtime_2);
            ChatClient.begintime = System.currentTimeMillis();//开始时间
            while (true) {
                boolean isOutTime = CodeUtils.outTime(ChatClient.begintime, ChatClient.overtime_30, "转账超时...", isReport);
                if (isOutTime) {
                    return;
                }
                UiObject zhuanzhang = mDevice.findObject(new UiSelector().text("转账").resourceId("com.chinamworld.main:id/tv_function"));
                if (zhuanzhang.exists()) {
                    showMsg("点击转账");
                    zhuanzhang.click();
                    break;
                }
            }
            sleep(ChatClient.overtime_2);
            //获取页面上登录节点
            ChatClient.begintime = System.currentTimeMillis();//开始时间
            while (true) {
                boolean isOutTime = CodeUtils.outTime(ChatClient.begintime, ChatClient.overtime_30, "账号超时...", isReport);
                if (isOutTime) {
                    return;
                }
                Log.e("报错点", "报错点1 ");
                UiObject login = mDevice.findObject(new UiSelector().resourceId("com.chinamworld.main:id/tv_userInfo"));
                if (login.exists()) {
                    UiObject pwd = mDevice.findObject(new UiSelector().resourceId("com.chinamworld.main:id/et_password"));
                    pwd.legacySetText("");
                    //截取键盘模拟用户输入登录密码
                    if (user.getPwd() != null) {
                        type = "abc";
                        setClick(user.getPwd());
                    }
                    Log.e("报错点", "报错点2");
                    sleep(ChatClient.overtime_2);
                    mDevice.click(967, 1245);
                    sleep(ChatClient.overtime_2);
                    break;
                }
            }
            while (true) {
                UiObject username = mDevice.findObject(new UiSelector().resourceId("com.chinamworld.main:id/tv_userInfo"));
                if (username.exists()) {
                    String name = username.getText();
                    if (!name.equals("身份信息获取中...")) {
                        if (name.equals("获取用户信息失败")) {
                            while (true) {
                                UiObject btn_getUserInfo = mDevice.findObject(new UiSelector().resourceId("com.chinamworld" +
                                        ".main:id/btn_getUserInfo"));
                                if (btn_getUserInfo.exists()) {
                                    btn_getUserInfo.click();
                                    break;
                                }
                            }
                        } else {
                            break;
                        }
                    }
                }
                Log.e("报错点", "报错点3");
            }
            //登录
            UiObject lgbut = mDevice.findObject(new UiSelector().resourceId("com.chinamworld.main:id/btn_confirm"));
            if (lgbut.exists())
                lgbut.click();
            setRemittance();
        } catch (Exception e) {
            setDevicesLog(e.toString());
            e.printStackTrace();
        }
    }

    /**
     * 登录成功后进入转账
     *
     * @throws UiObjectNotFoundException
     */
    public void setRemittance() {
        try {
            sleep(ChatClient.overtime_3);
            ChatClient.begintime = System.currentTimeMillis();//开始时间
            while (true) {
                boolean isOutTime = CodeUtils.outTime(ChatClient.begintime, ChatClient.overtime_30, "登录超时...", isReport);
                if (isOutTime) {
                    return;
                }
                UiObject remittance = CodeUtils.getUiObject_textOrId("转账", "com.chinamworld.main:id/ccb_title_text");
                UiObject close = mDevice.findObject(new UiSelector().resourceId("com.chinamworld.main:id/iv_red_packet_close"));
                if (remittance.exists()) {
                    CCBMethodName = "setTimerun";
                    //判断是否存在订单
                    ChatClient.loginS();
                    showMsg("=====上报登录成功========");
                    break;
                } else if (close.exists()) {
                    close.click();
                    sleep(ChatClient.overtime_1);
                    close();
                }
            }
            while (true) {
                sleep(ChatClient.overtime_3);
                RUNING = list.size() > 0;
                if (RUNING) {
                    orderBankName = Constants.getBank(list.get(0).getBankName(), "CCB");
                    if (ConfirmOrder) {
                        showMsg("====开始查账=====");
                        auditOrder();
                    } else {
                        showMsg("====开始转账=====");
                        remittanceLongin();
                    }
                } else {
                    if (PAUSE) {
                        setTimerun();
                    } else {
                        S_paused_C();
                        sleep(ChatClient.overtime_1);
                    }
                }
            }
        } catch (Exception e) {
            setDevicesLog(e.toString());
            e.printStackTrace();
        }
    }

    /**
     * 关闭抢红包弹窗
     *
     * @throws UiObjectNotFoundException
     */
    public void close() throws UiObjectNotFoundException {
        ChatClient.begintime = System.currentTimeMillis();//开始时间
        while (true) {
            boolean isOutTime = CodeUtils.outTime(ChatClient.begintime, ChatClient.overtime_5, "主页按钮超时1...", isReport);
            if (isOutTime) {
                return;
            }
            UiObject transfer = mDevice.findObject(new UiSelector().resourceId("com.chinamworld.main:id/main_home_smart_transfer"));
            if (transfer.exists()) {
                transfer.click();
                break;
            }
        }

        ChatClient.begintime = System.currentTimeMillis();//开始时间
        while (true) {
            boolean isOutTime = CodeUtils.outTime(ChatClient.begintime, ChatClient.overtime_5, "转账查找超时...", isReport);
            if (isOutTime) {
                return;
            }
            UiObject zhuanzhang = mDevice.findObject(new UiSelector().text("转账").resourceId("com.chinamworld.main:id/tv_function"));
            if (zhuanzhang.exists()) {
                zhuanzhang.click();
                break;
            }
        }
    }

    /**
     * 转账汇款
     */
    public void remittanceLongin() {
        try {
            showMsg("=====进入转账========");
            SMS_num = 0;
            CCBMethodName = "remittanceLongin";
            ChatClient.begintime = System.currentTimeMillis();//开始时间
            while (true) {
                boolean isOutTime = CodeUtils.outTime(ChatClient.begintime, ChatClient.overtime_5, ChatClient.errorStr, isReport);
                if (isOutTime) {
                    return;
                }
                UiObject function = mDevice.findObject(new UiSelector().text("转账").resourceId("com.chinamworld.main:id/tv_function"));
                UiObject username_ = mDevice.findObject(new UiSelector().resourceId("com.chinamworld.main:id/et_cash_name"));
                if (function.exists()) {
                    function.click();
                    sleep(ChatClient.overtime_2);
                } else if (username_.exists()) {
                    sleep(ChatClient.overtime_1);
                    username_.setText(list.get(0).getUserName());
                    showMsg("=====输入收款人======");
                    break;
                }
            }
            sleep(ChatClient.overtime_1);
            while (true) {
                UiObject moeny = mDevice.findObject(new UiSelector().resourceId("com.chinamworld.main:id/tv_pay_info"));
                if (moeny.exists()) {
                    if (moeny.getText().indexOf("-") == -1) {
                        String[] res = moeny.getText().split("  ");
                        sumMoney = res[2];
                        sumMoney = sumMoney.replaceAll(",", "");
                        C_updateBalance_W(Double.parseDouble(sumMoney));
                        showMsg("===本地保存余额===");
                        String sumMoneyFile = user.getUserName() + BANK_FLAG + "_sumMoney.txt";
                        FileHelper.saveMoneySDFile(false, sumMoney, sumMoneyFile);
                    }
                    break;
                }
            }
            sleep(ChatClient.overtime_1);
            showMsg("=====输入账卡号========");
            while (true) {
                UiObject bankNo_ = mDevice.findObject(new UiSelector().resourceId("com.chinamworld.main:id/et_collection_account"));
                if (bankNo_.exists()) {
                    bankNo_.click();
                    sleep(ChatClient.overtime_1);
                    bankNo_.setText(list.get(0).getBankNo());
                    sleep(ChatClient.overtime_1);
                    mDevice.click(1000, 1400);
                    break;
                }
            }
            sleep(ChatClient.overtime_1);
            //选择银行
            ChatClient.begintime = System.currentTimeMillis();//开始时间
            while (true) {
                boolean isOutTime = CodeUtils.outTime(ChatClient.begintime, ChatClient.overtime_3, "银行自动识别...", notReport);
                if (isOutTime) {
                    break;
                }
                UiObject bank = mDevice.findObject(new UiSelector().resourceId("com.chinamworld.main:id/tv_bank"));
                if (bank.exists()) {
                    String bankName = bank.getText();
                    if (bankName.contains("请选择收款银行")) {
                        bank.click();
                        showMsg("=====选择银行点击========");
                        sleep(2000);
                        boolean b = addBank();
                        sleep(ChatClient.overtime_2);
                        if (b) {
                            showMsg("=====银行选择完毕========");
                            break;
                        } else {
                            showMsg("=====银行选择失败========");
                            mDevice.pressBack();
                            return;
                        }
                    }
                }
            }
            sleep(ChatClient.overtime_2);
            //返回转账页面
            ChatClient.begintime = System.currentTimeMillis();//开始时间
            while (true) {
                boolean isOutTime = CodeUtils.outTime(ChatClient.begintime, ChatClient.overtime_30, "转账金额超时...", isReport);
                if (isOutTime) {
                    return;
                }
                UiObject money = CodeUtils.getUiObject_textOrId("请输入转账金额", "com.chinamworld.main:id/et_tran_amount");
                if (money.exists()) {
                    sleep(500);
                    if (list.size() > 0) {
                        money.setText(list.get(0).getMoney());
                        showMsg("=====金额输入完毕========");
                    } else {
                        showMsg("=====无转账订单========");
                    }
                    break;
                }
            }

            showMsg("====获取金额====");
            if (sumMoney.equals("")) {
                sumMoney = "-1";
            } else {
                showMsg("===本地保存余额====:");
                String sumMoneyFile = user.getUserName() + BANK_FLAG + "_sumMoney.txt";
                FileHelper.saveMoneySDFile(false, sumMoney, sumMoneyFile);
            }
            //账户余额是否大于转账金额
            if (Double.parseDouble(sumMoney) < Double.parseDouble(list.get(0).getMoney())) {
                showMsg("===余额不足====");
                ChatClient.reportTransferOrder(BANK_NAME, "账户余额不足", sumMoney, 1);
                sleep(ChatClient.overtime_2);
                return;
            }
            mDevice.drag(200, 500, 540, 0, 20);//这里坐标不用转换
            showMsg("===滑动完成====");
            sleep(ChatClient.overtime_3);
            ChatClient.begintime = System.currentTimeMillis();//开始时间
            while (true) {
                boolean isOutTime = CodeUtils.outTime(ChatClient.begintime, ChatClient.overtime_5, "点击下一步===坐标点击...", notReport);
                if (isOutTime) {
                    mDevice.click((int) (540 * ratio), (int) (1240 * ratio));
                    break;
                }
                UiObject ok = mDevice.findObject(new UiSelector().resourceId("com.chinamworld.main:id/btn_right1"));
                UiObject ok1 = CodeUtils.getUiObject_containTextOrClass("下一步", "android.widget.Button");
                showMsg("-----檢測下一步按鈕-----");
                if (ok.exists() || ok1.exists()) {
                    if (ok.exists()) {
                        ok.click();
                        showMsg("===点击下一步====ID点击1");
                    }
                    if (ok1.exists()) {
                        ok1.click();
                        showMsg("===点击下一步====ID点击2");
                    }
                    CCBMethodName = "Submit";//提交
                    sleep(ChatClient.overtime_2);
                    break;
                }
            }

            ChatClient.begintime = System.currentTimeMillis();//开始时间
            while (true) {
                boolean isOutTime = CodeUtils.outTime(ChatClient.begintime, ChatClient.overtime_5, "检测查询帐户开户机构失败超时...", notReport);
                if (isOutTime) {
                    break;
                }
                UiObject text = mDevice.findObject(new UiSelector().className("android.widget.TextView").resourceId("com" +
                        ".chinamworld.main:id/tv_dlg_content"));
                UiObject sure = mDevice.findObject(new UiSelector().className("android.widget.TextView").resourceId("com" +
                        ".chinamworld.main:id/dlg_right_tv"));
                if (text.exists() && sure.exists()) {
                    String s = text.getContentDescription();
                    String s1 = text.getText();
                    if (s.contains("查询帐户开户机构失败") || s1.contains("查询帐户开户机构失败")) {
                        showMsg("===检测到查询帐户开户机构失败===");
                        sure.click();
                        closeSystem("查询帐户开户机构失败");
                        return;
                    }
                }
            }

            showMsg("===检测是否点击了下一步按钮===");
            ChatClient.begintime = System.currentTimeMillis();//开始时间
            while (true) {
                boolean isOutTime = CodeUtils.outTime(ChatClient.begintime, ChatClient.overtime_5, "再次检测下一步按钮超时...", notReport);
                if (isOutTime) {
                    break;
                }
                UiObject ok = mDevice.findObject(new UiSelector().resourceId("com.chinamworld.main:id/btn_right1"));
                UiObject ok1 = CodeUtils.getUiObject_containTextOrClass("下一步", "android.widget.Button");
                showMsg("===第二次檢測下一步按鈕===");
                if (ok.exists() || ok1.exists()) {
                    showMsg("===第二次检测到下一步按鈕===点击坐标");
                    mDevice.click(540, (int) (1240 * ratio));
                    break;
                }
                sleep(ChatClient.overtime_1);
            }
            sleep(ChatClient.overtime_2);
            if (isOverMax(list.get(0).getMoney())) {
                showMsg("---开户行信息---");
                String[] array = list.get(0).getBankAdr().split("-");
                List<String> bankInfo = new ArrayList<>();
                String s = "";
                for (int i = 0; i < array.length; i++) {
                    if (i < 2) {
                        bankInfo.add(array[i]);
                    } else {
                        if (array.length == 3) {
                            bankInfo.add(array[i]);
                        } else {
                            showMsg("----开户行截取超过3---");
                            if (i == 2) {
                                s += array[i];
                            } else {
                                s += "-" + array[i];
                            }
                            showMsg("----拼接开户行后面的字段---");
                            if (i == array.length - 1) {
                                showMsg("----拼接完成---");
                                bankInfo.add(s);
                            }
                        }
                    }
                }
                sleep(ChatClient.overtime_2);
                showMsg("===准备进入选择省份====");
                chooseProvice(bankInfo.get(0));
                sleep(ChatClient.overtime_2);
                showMsg("===准备进入选择城市====");
                addWorkTime(ChatClient.overtime_30);
                chooseCity(bankInfo.get(1));
                sleep(ChatClient.overtime_2);
                showMsg("===准备进入选择具体支行====");
                addWorkTime(ChatClient.overtime_10);
                chooseBank(bankInfo.get(2));
                sleep(ChatClient.overtime_8);
                showMsg("===准备进入测试返回====");
            } else {
                finishOrder();
            }
        } catch (Exception e) {
            setDevicesLog(e.toString());
            e.printStackTrace();
        }
    }

    /**
     * 银行系统关闭
     */
    private void closeSystem(String s) throws UiObjectNotFoundException {
        showMsg("银行大额转账系统关闭");
        sendUnBankInfo(s);
        sleep(ChatClient.overtime_2);
        while (true) {
            UiObject back = mDevice.findObject(new UiSelector().className("android.widget.Button").resourceId("com.chinamworld" +
                    ".main:id/ccb_title_left_btn"));
            if (back.exists()) {
                showMsg("--点击返回--");
                back.click();
                break;
            }
        }
        sleep(ChatClient.overtime_8);
        ChatClient.begintime = System.currentTimeMillis();//开始时间
        while (true) {
            boolean isOutTime = CodeUtils.outTime(ChatClient.begintime, ChatClient.overtime_30, "检测控件超时...", notReport);
            if (isOutTime) {
                return;
            }
            UiObject zhuanzhang = CodeUtils.getUiObject_textOrId("预约转账", "com.chinamworld.main:id/tv_function");
            if (zhuanzhang.exists()) {
                mDevice.click((int) (87 * ratio), (int) (247 * ratio));
                showMsg("===转账完成进入转账页面=====");
                break;
            }
        }
    }

    /**
     * 完成转账流程
     */
    private void finishOrder() throws UiObjectNotFoundException {
        CCBMethodName = "remittanceLongin";
        showMsg("====继续====1====");
        ChatClient.begintime = System.currentTimeMillis();//开始时间
        while (true) {
            boolean isOutTime = CodeUtils.outTime(ChatClient.begintime, ChatClient.overtime_30, "完成页超时...", isReport);
            if (isOutTime) {
                return;
            }
            UiObject jx = CodeUtils.getUiObject_textOrId("继续", "com.chinamworld.main:id/dlg_right_tv");
            UiObject qr = mDevice.findObject(new UiSelector().resourceId("com.chinamworld.main:id/btn_confirm").text("确定"));//确认按钮
            UiObject code = mDevice.findObject(new UiSelector().resourceId("com.chinamworld.main:id/tv_title").text("请输入验证码"));
            UiObject btn_right1 = mDevice.findObject(new UiSelector().resourceId("com.chinamworld.main:id/btn_right1").text("下一步"));
            showMsg("====继续====2====");
            if (jx.exists()) {
                jx.click();
                showMsg("===点击继续====");
                break;
            } else if (qr.exists()) {
                qr.click();
                showMsg("===确认====");
                break;
            } else if (code.exists()) {
                showMsg("===请输入验证码====");
                break;
            } else if (btn_right1.exists()) {
                btn_right1.click();
                showMsg("===下一步====");
            }
        }
        showMsg("=====TV_TIPS=======2=");
        addWorkTime(ChatClient.overtime_60);
        sleep(ChatClient.overtime_2);
        getCodeType();
        CCBMethodName = "Re_send";
        //判断是否获取到短信
        ChatClient.begintime = System.currentTimeMillis();//开始时间
        while (true) {
            boolean isOutTime = CodeUtils.outTime(ChatClient.begintime, ChatClient.overtime_180, "《重新获取》超时...", isReport);
            if (isOutTime) {
                break;
            }
            //转账结果页面
            UiObject result = mDevice.findObject(new UiSelector().resourceId("com.chinamworld.main:id/ccb_title_right_btn"));
            if (getState(Constants.SMSMESSAGE, Constants.TV_TIPS)) {
                showMsg("===短信验证码获取成功====");
                break;
            } else if (result.exists()) {
                showMsg("===免验证====");
                ChatClient.msg("<YZF>{'header':'" + ChatClient.M_TRANSFERFINISH_P + "'}</YZF>");
                getUserInfo(sumMoney);
                return;
            } else {
                if (smsNumExceed()) {
                    return;
                }
                while (true) {
                    UiObject text_code = CodeUtils.getUiObject_textOrId("重新获取", "com.chinamworld.main:id/re_send");
                    if (text_code.exists()) {
                        text_code.click();
                        showMsg("===重新获取验证码1====");
                        sleep(ChatClient.overtime_10);
                        getCodeType();
                        break;
                    }
                }
            }
        }
        while (true) {
            boolean isOutTime = CodeUtils.outTime(ChatClient.begintime, ChatClient.overtime_30, "验证码超时...", isReport);
            if (isOutTime) {
                return;
            }
            UiObject et_code = mDevice.findObject(new UiSelector().resourceId("com.chinamworld.main:id/et_code"));
            if (et_code.exists()) {
                showMsg("===弹出验证码输入键盘===");
                et_code.click();
                break;
            }
        }
        sleep(ChatClient.overtime_1);
        showMsg("===开始输入验证码====");
        if (user.getUseType().equals("1")) {
            setClickXunFeiN(Constants.CODE);
        } else {
            setClickXunFeiN(ChatClient.smsCode.getSmscode());
        }
        showMsg("===验证码输入完毕====");
        Constants.TV_TIPS = "";
        //完成
        sleep(ChatClient.overtime_2);
        showMsg("===收起验证码键盘===");
        mDevice.click(990, 1340);
        sleep(ChatClient.overtime_2);
        //判断金额是否超过30W
        UiObject checkbox = mDevice.findObject(new UiSelector().resourceId("com.chinamworld.main:id/checkbox"));
        if (checkbox.exists()) {
            showMsg("===金额超过30W===");
            checkbox.click();
        }
        sleep(ChatClient.overtime_1);
        ChatClient.begintime = System.currentTimeMillis();//开始时间
        while (true) {
            boolean isOutTime = CodeUtils.outTime(ChatClient.begintime, ChatClient.overtime_30, "验证码确定超时...", notReport);
            if (isOutTime) {
                mDevice.click(360, 50);
                break;
            }
            sleep(ChatClient.overtime_1);
            UiObject sure = mDevice.findObject(new UiSelector().className("android.widget.Button").resourceId("com.chinamworld" +
                    ".main:id/btn_confirm"));
            showMsg("===检测验证码确定按钮===");
            if (sure.exists()) {
                showMsg("===点击验证码确定===");
                sure.click();
                break;
            }
        }
        sleep(ChatClient.overtime_2);
        showMsg("===确定点击完成====");
        ChatClient.begintime = System.currentTimeMillis();//开始时间
        while (true) {
            boolean isOutTime = CodeUtils.outTime(ChatClient.begintime, ChatClient.overtime_3, "验证码超时...", notReport);
            if (isOutTime) {
                break;
            }
            UiObject smsErrorUiObject = mDevice.findObject(new UiSelector().resourceId("com.chinamworld.main:id/tv_dlg_content"));
            if (smsErrorUiObject.exists()) {
                if (errorCodeRecord(smsErrorUiObject)) {
                    showMsg("===检测验证码错误=====");
                } else {
                    showMsg("===检测验证码正确=====");
                }
            }

        }
        Constants.CODE = "";
        Constants.SMSMESSAGE = "";
        Constants.TV_TIPS = "";
        CODE_TIMER = 0;
        //附加图形验证码
        ChatClient.begintime = System.currentTimeMillis();//开始时间
        while (true) {
            boolean isOutTime = CodeUtils.outTime(ChatClient.begintime, ChatClient.overtime_5, "附加码超时...", notReport);
            if (isOutTime) {
                break;
            }
            sleep(ChatClient.overtime_1);
            UiObject fpwd1 = mDevice.findObject(new UiSelector().text("请输入附加码"));
            if (!fpwd1.exists()) {
                fpwd1 = mDevice.findObject(new UiSelector().descriptionContains("请输入附加码"));
            }
            if (fpwd1.exists()) {
                sleep(ChatClient.overtime_2);
                isCode = true;
                showMsg("===请输入附加码===");
                imageCode_f();
                break;
            }
        }
        showMsg("===附加码输入完毕=====");
        //取款密码
        ChatClient.begintime = System.currentTimeMillis();//开始时间
        while (true) {
            boolean isOutTime = CodeUtils.outTime(ChatClient.begintime, ChatClient.overtime_5, "获取图片验证码超时...", notReport);
            if (isOutTime) {
                break;
            }
            UiObject fpwd0 = mDevice.findObject(new UiSelector().text("重新输入").className("android.widget.TextView"));
            UiObject fpwd1 = mDevice.findObject(new UiSelector().text("重新输入").className("android.widget.Button"));
            //图形验证码
            UiObject bpwd = CodeUtils.getUiObject_textOrId("请输入账户取款密码", "com.chinamworld.main:id/tv_title");
            //转账结果页面
            UiObject result = mDevice.findObject(new UiSelector().resourceId("com.chinamworld.main:id/ccb_title_right_btn"));
            showMsg("==========检测获取图片验证码=============");
            if (fpwd0.exists()) {
                fpwd0.click();
                showMsg("===重新获取附加码验证=====");
                sleep(ChatClient.overtime_1);
                isCode = true;
                imageCode_f();
                sleep(ChatClient.overtime_2);
                ChatClient.begintime = System.currentTimeMillis();//开始时间
            } else if (fpwd1.exists()) {
                fpwd1.click();
                showMsg("===重新获取附加码验证1=====");
                sleep(ChatClient.overtime_1);
                isCode = true;
                imageCode_f();
                sleep(ChatClient.overtime_2);
                ChatClient.begintime = System.currentTimeMillis();//开始时间
            } else if (bpwd.exists()) {
                showMsg("===输入取款密码====1=");
                sleep(ChatClient.overtime_1);
                ChatClient.begintime = System.currentTimeMillis();//开始时间
                BankPwd();
                break;
            } else if (result.exists()) {
                sleep(ChatClient.overtime_1);
                break;
            }
        }
        showMsg("===准备检测是否附加码输入错误===");
        if (isCode) {
            showMsg("===附加码错误弹框出现===");
            checkNumberDialog();
        } else {
            showMsg("===没有出现附加码错误弹框===");
        }
        showMsg("===数组长度1====" + list.size());
        ChatClient.begintime = System.currentTimeMillis();//开始时间
        addWorkTime(ChatClient.overtime_20);
        showMsg("===检测是否有限额弹框====");
        //检测是否有限额提醒
        while (true) {
            boolean isOutTime = CodeUtils.outTime(ChatClient.begintime, ChatClient.overtime_3, "验证码超时...", notReport);
            if (isOutTime) {
                break;
            }
            sleep(ChatClient.overtime_1);
            UiObject text = mDevice.findObject(new UiSelector().resourceId("com.chinamworld.main:id/tv_dlg_content"));
            UiObject sure = CodeUtils.getUiObject_textOrId("确定", "com.chinamworld.main:id/dlg_right_tv");
            showMsg("===检测限额弹框=====");
            if (sure.exists()) {
                String info = text.getText();
                sure.click();
                sleep(2000);
                showMsg("===向电脑端发送待处理信息=====" + info);
                sendRePropcessInfo(info);
                return;
            }
        }
        showMsg("===检测限额完成====" + list.size());
        CODE_TIMER = 0;
        ChatClient.msg("<YZF>{'header':'" + ChatClient.M_TRANSFERFINISH_P + "'}</YZF>");
        getUserInfo(sumMoney);
    }

    private boolean errorCodeRecord(UiObject ui) throws UiObjectNotFoundException {
        String errorTag = "验证码有误";
        if (!TextUtils.isEmpty(ui.getText()) && ui.getText().contains(errorTag)) {
            if (smsNumExceed()) {
                return true;
            }
            UiObject closeUi = mDevice.findObject(new UiSelector().resourceId("com.chinamworld" +
                    ".main:id/dlg_right_tv"));
            if (closeUi.exists()) {
                closeUi.click();
                sleep(ChatClient.overtime_1);
                UiObject ok = mDevice.findObject(new UiSelector().resourceId("com.chinamworld.main:id/btn_right1"));
                UiObject ok1 = mDevice.findObject(new UiSelector().text("下一步").className("android.widget.Button"));
                UiObject ok2 = mDevice.findObject(new UiSelector().descriptionContains("下一步").className("android.widget.Button"));
                showMsg("===errorCodeRecord檢測下一步按鈕===");
                if (ok.exists() || ok1.exists() || ok2.exists()) {
                    showMsg("===errorCodeRecord检测到下一步按鈕===" + "点击坐标");
                    mDevice.click(540, (int) (1240 * ratio));
                    mDevice.click(540, (int) (1240 * ratio));
                }
                sleep(ChatClient.overtime_1);

                ChatClient.begintime = System.currentTimeMillis();//开始时间
                while (true) {
                    boolean isOutTime = CodeUtils.outTime(ChatClient.begintime, ChatClient.overtime_180, "重新获取超时...", isReport);
                    if (isOutTime) {
                        return false;
                    }
                    if (getState(Constants.SMSMESSAGE, Constants.TV_TIPS)) {
                        showMsg("===短信验证码获取成功====");
                        break;
                    }
                    if (smsNumExceed()) {
                        return true;
                    }
                    while (true) {
                        UiObject text_code = CodeUtils.getUiObject_textOrId("重新获取", "com.chinamworld.main:id/re_send");
                        if (text_code.exists()) {
                            showMsg("===重新获取验证码2====");
                            ChatClient.addWorkTime(ChatClient.overtime_60);
                            text_code.click();
                            sleep(ChatClient.overtime_10);
                            getCodeType();
                            break;
                        }
                    }
                }
                while (true) {
                    boolean isOutTime = CodeUtils.outTime(ChatClient.begintime, ChatClient.overtime_30, "errorCodeRecord...", isReport);
                    if (isOutTime) {
                        return false;
                    }
                    UiObject et_code = mDevice.findObject(new UiSelector().resourceId("com.chinamworld.main:id/et_code"));
                    if (et_code.exists()) {
                        et_code.click();
                        showMsg("===弹出验证码输入键盘=====");
                        break;
                    }
                }
                sleep(ChatClient.overtime_1);
                showMsg("===开始输入验证码====");
                if (user.getUseType().equals("1")) {
                    setClickXunFeiN(Constants.CODE);
                } else {
                    setClickXunFeiN(ChatClient.smsCode.getSmscode());
                }
                showMsg("===验证码输入完毕====");
                Constants.TV_TIPS = "";
                //完成
                sleep(ChatClient.overtime_2);
                showMsg("===收起验证码键盘=====");
                mDevice.click(990, 1340);
                sleep(ChatClient.overtime_2);
                //判断金额是否超过30W
                UiObject checkbox = mDevice.findObject(new UiSelector().resourceId("com.chinamworld.main:id/checkbox"));
                if (checkbox.exists()) {
                    showMsg("===金额超过30W=====");
                    checkbox.click();
                }
                ChatClient.begintime = System.currentTimeMillis();//开始时间
                sleep(ChatClient.overtime_1);
                while (true) {
                    boolean isOutTime = CodeUtils.outTime(ChatClient.begintime, ChatClient.overtime_30, "验证码确定超时...", notReport);
                    if (isOutTime) {
                        mDevice.click(360, 1050);
                        break;
                    }
                    sleep(ChatClient.overtime_2);
                    UiObject sure = mDevice.findObject(new UiSelector().className("android.widget.Button").resourceId("com.chinamworld" +
                            ".main:id/btn_confirm"));
                    showMsg("===检测验证码确定按钮=====");
                    if (sure.exists()) {
                        showMsg("===点击验证码确定=====");
                        sure.click();
                        break;
                    }
                }
                sleep(ChatClient.overtime_2);
                showMsg("===确定点击完成=====");
                ChatClient.begintime = System.currentTimeMillis();//开始时间
                while (true) {
                    boolean isOutTime = CodeUtils.outTime(ChatClient.begintime, ChatClient.overtime_3, "......", notReport);
                    if (isOutTime) {
                        break;
                    }
                    UiObject smsErrorUiObject = mDevice.findObject(new UiSelector().resourceId("com.chinamworld.main:id/tv_dlg_content"));
                    if (smsErrorUiObject.exists()) {
                        if (errorCodeRecord(smsErrorUiObject)) {
                        }
                    }
                }
                return true;
            } else {
                return false;
            }
        }
        return false;
    }

    /**
     * 判断短信发送次数是否超时
     */
    private boolean smsNumExceed() {
        //短信请求三次重启
        if (SMS_num < 2) {
            SMS_num += 1;
            return false;
        } else {
            ChatClient.timer(LogToFile.getMethodName(), "短信请求超次重启...");
            return true;
        }
    }


    /**
     * 检测三次附加码
     */
    private void checkNumberDialog() throws UiObjectNotFoundException {
        sleep(ChatClient.overtime_1);
        //附加码错误
        showMsg("第一次检测附加码错误提示");
        checkErrorDialog(1);
        sleep(ChatClient.overtime_1);
        showMsg("第二次检测附加码错误提示");
        checkErrorDialog(2);
        showMsg("===附加码输入完毕=====");
    }

    /**
     * 请求短信
     *
     * @param args1
     * @param args2
     * @return
     */
    public boolean getState(String args1, String args2) {
        showMsg("=短信内容===args1===" + args1 + "===短信识别码==args2===" + args2 + "===短信识别码===getUseType===" + user.getUseType());
        addWorkTime(ChatClient.overtime_20);
        if (!user.getUseType().equals("1")) {
            if (SMS_num > 0) {
                sleep(ChatClient.overtime_25);
                showMsg("第二次获取");
            }
            showMsg("第" + SMS_num + "次获取短信");
            ChatClient.requestSMSCode(user.getUserName(), user.getBankId());
            if (TextUtils.isEmpty(ChatClient.smsCode.getSmscode())) {
                return false;
            } else {
                if (ChatClient.smsCode.getTelephone().equals(user.getUserName())) {
                    showMsg("收到短信验证码：" + ChatClient.smsCode.getSmscode());
                    return true;
                } else {
                    String str = "收到短信验证码手机号不匹配";
                    showMsg(str + ChatClient.smsCode.getTelephone());
                    return false;
                }
            }
        } else {
            if (!args1.equals("") && !args2.equals("")) {
                String[] res = args2.split("发送");
                String sumMoney = res[1];
                sumMoney = sumMoney.replaceAll("为", "");
                showMsg("sumMoney = " + sumMoney);
                if (args1.contains(sumMoney)) {
                    System.out.println("包含");
                    return true;
                } else {
                    System.out.println("不包含");
                    return false;
                }
            } else {
                return false;
            }
        }
    }

    /**
     * 检测附加码错误提示 弹框
     *
     * @param i
     **/
    private void checkErrorDialog(int i) throws UiObjectNotFoundException {
        addWorkTime(ChatClient.overtime_10);
        ChatClient.begintime = System.currentTimeMillis();//开始时间
        while (true) {
            boolean isOutTime = CodeUtils.outTime(ChatClient.begintime, ChatClient.overtime_5, "第" + i + "次检测附加码错误提示超时...", notReport);
            if (isOutTime) {
                return;
            }
            sleep(ChatClient.overtime_1);
            UiObject notice = CodeUtils.getUiObject_textOrId("图形验证码不正确，请重新输入！", "com.chinamworld.main:id/tv_dlg_content");
            showMsg("===检测是否有附加码错误提示=====");
            if (notice.exists()) {
                clickReBtn();
                break;
            }
        }
        showMsg("====再次获取附加码====");
        sleep(ChatClient.overtime_1);
        ChatClient.begintime = System.currentTimeMillis();//开始时间
        while (true) {
            boolean isOutTime = CodeUtils.outTime(ChatClient.begintime, ChatClient.overtime_3, "《附加码》超时...", notReport);
            if (isOutTime) {
                break;
            }
            UiObject fpwd1 = mDevice.findObject(new UiSelector().text("请输入附加码").resourceId("com.chinamworld.main:id/tv_title"));
            if (fpwd1.exists()) {
                sleep(ChatClient.overtime_1);
                showMsg("===请输入附加码===");
                imageCode_f();
                break;
            }
        }
    }

    /**
     * 点击图形验证码重新输入
     */
    private void clickReBtn() throws UiObjectNotFoundException {
        showMsg("===准备点击附加码重新输入=====");
        while (true) {
            UiObject ok = CodeUtils.getUiObject_textOrId("重新输入", "com.chinamworld.main:id/dlg_right_tv");
            if (ok.exists()) {
                showMsg("===点击附加码重新输入====");
                ok.click();
                sleep(ChatClient.overtime_1);
                imageCode_f();
                sleep(ChatClient.overtime_2);
                break;
            }
        }
    }

    /**
     * 判断是否达到选择开户行的临界值
     *
     * @path sumMoney
     */
    private boolean isOverMax(String s) {
        boolean b = false;
        double c = 50000.00;//临界值为50000.00
        showMsg("===判断金额是否超过填写开户行的临界值===");
        double money = Double.parseDouble(s);
        if (money > c) {
            b = true;
        }
        showMsg("===判断金额是否超过填写开户行的临界值===" + b);
        return b;
    }

    /**
     * 选择具体网点
     */
    private void chooseBank(String s) throws UiObjectNotFoundException {
        sleep(ChatClient.overtime_2);
        showMsg("===支行信息====" + s);
        while (true) {
            UiObject etSearch = mDevice.findObject(new UiSelector().className("android.widget.EditText").resourceId("com.chinamworld" +
                    ".main:id/search_et"));
            showMsg("===查找搜索控件====");
            if (etSearch.exists()) {
                showMsg("===找到搜索控件===");
                etSearch.setText(s);
                UiObject list = mDevice.findObject(new UiSelector().className("android.widget.ListView").resourceId("com.chinamworld" +
                        ".main:id/cslhl_content"));
                /**
                 * 适配金立
                 */
                UiObject view = null;
                view = list.getChild(new UiSelector().className("android.view.ViewGroup").index(0));
                showMsg("===搜索银行====");
                if (view.exists()) {
                    showMsg("===点击银行支行====");
                    view.click();
                    break;
                } else {
                    showMsg("===未搜索到银行====");
                    UiObject layout = mDevice.findObject(new UiSelector().className("android.widget.LinearLayout").resourceId("com" +
                            ".chinamworld.main:id/ll_no_result"));
                    UiObject img = layout.getChild(new UiSelector().className("android.widget.ImageView").index(0));
                    showMsg("===检测未搜索到银行====");
                    if (img.exists()) {
                        UiObject close = mDevice.findObject(new UiSelector().className("android.widget.ImageButton").resourceId("com" +
                                ".chinamworld.main:id/cib_close"));
                        showMsg("===检测支行的关闭键====");
                        if (close.exists()) {
                            close.click();
                            returnBack("未找到该银行的开户行信息");
                            return;
                        }
                    }
                }
            }
        }
        finishOrder();
    }

    /**
     * 未搜索到网点返回
     */
    private void returnBack(String s) throws UiObjectNotFoundException {
        CCBMethodName = "remittanceLongin";
        sendUnBankInfo(s);
        showMsg("===上报未搜索到开户网点====");
        sleep(ChatClient.overtime_2);
        while (true) {
            UiObject tv = mDevice.findObject(new UiSelector().text("收款网点").className("android.widget.TextView").resourceId("com" +
                    ".chinamworld.main:id/ctv_title"));
            showMsg("===准备检测城市的关闭键====");
            if (tv.exists()) {
                UiObject close = mDevice.findObject(new UiSelector().className("android.widget.ImageButton").resourceId("com" +
                        ".chinamworld.main:id/cib_close"));
                if (close.exists()) {
                    showMsg("===点击城市的关闭键====");
                    close.click();
                    break;
                }
            }
        }
        sleep(ChatClient.overtime_2);
        while (true) {
            UiObject tv = mDevice.findObject(new UiSelector().text("收款网点").className("android.widget.TextView").resourceId("com" +
                    ".chinamworld.main:id/ctv_title"));
            showMsg("===准备检测省份的关闭键====");
            if (tv.exists()) {
                UiObject close = mDevice.findObject(new UiSelector().className("android.widget.ImageButton").resourceId("com" +
                        ".chinamworld.main:id/cib_close"));
                if (close.exists()) {
                    showMsg("===点击省份的关闭键====");
                    close.click();
                    break;
                }
            }
        }
        sleep(ChatClient.overtime_2);
        while (true) {
            UiObject tv = mDevice.findObject(new UiSelector().text("转账").className("android.widget.TextView").resourceId("com" +
                    ".chinamworld.main:id/ccb_title_text"));
            showMsg("===准备检测转账的关闭键====");
            if (tv.exists()) {
                UiObject back = mDevice.findObject(new UiSelector().className("android.widget.Button").resourceId("com.chinamworld" +
                        ".main:id/ccb_title_left_btn"));
                if (back.exists()) {
                    showMsg("===点击转账的关闭键====");
                    back.click();
                    break;
                }
            }
        }
        sleep(ChatClient.overtime_8);
        ChatClient.begintime = System.currentTimeMillis();//开始时间
        while (true) {
            boolean isOutTime = CodeUtils.outTime(ChatClient.begintime, ChatClient.overtime_30, "验证码确定超时...", isReport);
            if (isOutTime) {
                mDevice.click(360, 1050);
                return;
            }
            UiObject zhuanzhang = CodeUtils.getUiObject_textOrId("预约转账", "com.chinamworld.main:id/tv_function");
            if (zhuanzhang.exists()) {
                mDevice.click((int) (87 * ratio), (int) (247 * ratio));
                showMsg("===转账完成进入转账页面===");
                break;
            }
        }
    }

    /**
     * 选择城市
     */
    private void chooseCity(String city) {
        try {
            int textPosition = 0;
            showMsg("===准备选择市====");
            while (true) {
                sleep(2000);
                showMsg("---城市---");
                String s1 = PinYinUtil.getPinYinFirstHeadChar(city);
                UiObject list = mDevice.findObject(new UiSelector().className("android.widget.ListView").resourceId("com.chinamworld" +
                        ".main:id/cslhl_content"));
                UiObject view = list.getChild(new UiSelector().className("android.view.ViewGroup").index(textPosition));
                showMsg("===查找控件，位置为====" + textPosition);
                if (list.exists()) {
                    if (view.exists()) {
                        UiObject text = view.getChild(new UiSelector().className("android.widget.TextView").index(0));
                        if (text.exists()) {
                            String s2 = text.getText();
                            showMsg("===找到标签====" + s2);
                            if (s1.equals(s2)) {
                                showMsg("===找到标签====");
                                clickCity(view, city);
                                break;
                            } else {
                                if (s2.contains("银行")) {
                                    showMsg("===进入到选择支行界面，跳出循环====");
                                    break;
                                } else {
                                    addWorkTime(ChatClient.overtime_10);
                                    showMsg("===未找到标签====" + s1 + "与" + s2 + "不匹配");
                                    textPosition++;
                                }
                            }
                        } else {
                            showMsg("===未找到标签控件====");
                            textPosition++;
                        }
                    } else {
                        showMsg("===未找到标签====" + "当前位置为:" + textPosition);
                        if (textPosition == 0) {//判断是否为0位置防止不停的的滑动
                            textPosition = 1;
                        } else {
                            showMsg("===未找到标签，向上滑动====");
                            mDevice.drag(200, 700, 540, 0, 30);//这里坐标不用转换
                            addWorkTime(ChatClient.overtime_10);
                            showMsg("===滑动====");
                            sleep(ChatClient.overtime_2);
                            textPosition = 0;
                        }
                    }
                }
            }
        } catch (UiObjectNotFoundException e) {
            e.printStackTrace();
        }
    }

    /**
     * 找到对应的城市点击
     *
     * @param view
     * @param s
     */
    private void clickCity(UiObject view, String s) throws UiObjectNotFoundException {
        sleep(2000);
        int position = 0;
        int times = 0;
        while (true) {
            sleep(2000);
            UiObject layout = view.getChild(new UiSelector().className("android.widget.LinearLayout").index(1));
            if (layout.exists()) {
                UiObject text = layout.getChild(new UiSelector().className("android.widget.TextView").index(position));
                if (text.exists()) {
                    showMsg("===找到控件====");
                    String city = text.getText();
                    showMsg("===找到控件====" + city);
                    if (city.contains(s)) {
                        text.click();
                        showMsg("===点击城市====");
                        times = 0;
                        break;
                    } else {
                        showMsg("===城市不匹配====" + position);
                        showMsg("===滑动====");
                        position += 2;
                    }
                } else {
                    showMsg("位置" + position + "未找到控件");
                    times++;
                    if (times > 3) {
                        times = 0;
                        showMsg("===未找到控件，向上滑动====");
                        mDevice.drag(200, 700, 540, 0, 30);//这里坐标不用转换
                        getCity(s, position);
                        break;
                    }
                }
            } else {
                showMsg("===找不到控件====" + position);
                times++;
                if (times > 3) {
                    times = 0;
                    showMsg("===未找到标签，向上滑动====");
                    mDevice.drag(200, 700, 540, 0, 30);//这里坐标不用转换
                    getCity(s, position);
                    break;
                }
            }
        }
    }

    /**
     * 继续查找城市,判断是否存在标签
     */
    private void getCity(String s, int position) throws UiObjectNotFoundException {
        sleep(2000);
        String s1 = PinYinUtil.getPinYinFirstHeadChar(s);
        showMsg("准备比对标签:" + s1);
        int times = 0;
        while (true) {
            UiObject tab = CodeUtils.getUiObject_containTextOrClass(s1, "android.widget.TextView");
            if (tab.exists()) {
                showMsg("字母标签存在，查找城市");
                getTabToCity(s);
                break;
            } else {
                times++;
                if (times > 3) {
                    times = 0;
                    showMsg("字母标签不存在，查找城市");
                    getNoTabToCity(s, position);
                    break;
                }
            }
        }
    }

    /**
     * 标签不存在  继续查找城市
     */
    private void getNoTabToCity(String s, int position) throws UiObjectNotFoundException {
        int times = 0;
        while (true) {
            UiObject list = mDevice.findObject(new UiSelector().className("android.widget.ListView").resourceId("com.chinamworld" +
                    ".main:id/cslhl_content"));
            UiObject view = null;
            view = list.getChild(new UiSelector().className("android.view.ViewGroup").index(0));
            UiObject layout = view.getChild(new UiSelector().className("android.widget.LinearLayout").index(0));
            UiObject text = layout.getChild(new UiSelector().className("android.widget.TextView").index(position));
            showMsg("===没有字母标签，查找具体的城市====");
            if (text.exists()) {
                String s1 = text.getText();
                showMsg("===没有字母标签，找到的城市====" + s1);
                if (s1.contains(s)) {
                    showMsg("===没有字母标签，找到的城市====" + s1 + "与所要查找的" + s + "一致");
                    text.click();
                    break;
                } else {
                    showMsg("===城市不匹配====");
                    position += 2;
                }
            } else {
                times++;
                if (times > 3) {
                    times = 0;
                    mDevice.drag(200, 700, 540, 0, 30);//这里坐标不用转换
                    showMsg("------滑动----");
                    position += 2;
                }
            }
        }
    }

    /**
     * 标签存在  继续查找城市
     */
    private void getTabToCity(String s) {
        chooseCity(s);
    }

    /**
     * 选择省份
     *
     * @param s
     */
    private void chooseProvice(String s) {
        try {
            showMsg("---省份----" + s);
            s = s.replace("省", "");
            showMsg("---将传过来的省去掉----");
            while (true) {
                sleep(ChatClient.overtime_2);
                String s1 = PinYinUtil.getPinYinFirstHeadChar(s);
                showMsg("===获取首字母====");
                UiObject list = mDevice.findObject(new UiSelector().className("android.widget.ListView").resourceId("com.chinamworld" +
                        ".main:id/cslhl_content"));
                UiObject normal = list.getChild(new UiSelector().text("常用").className("android.widget.TextView"));
                showMsg("===常用匹配====");
                if (normal.exists()) {
                    UiObject layout = list.getChild(new UiSelector().className("android.widget.LinearLayout").index(1));
                    UiObject text = layout.getChild(new UiSelector().className("android.widget.TextView").index(0));
                    showMsg("===通过常用匹配====");
                    if (text.exists()) {
                        String s2 = text.getText();
                        if (s.equals(s2)) {
                            text.click();
                            showMsg("===通过常用匹配到城市====" + s2);
                        } else {
                            showMsg("===未通过常用匹配到城市====" + s1);
                            check(s1, s);
                        }
                        break;
                    }
                }
            }
        } catch (UiObjectNotFoundException e) {
            e.printStackTrace();
        }
    }

    /**
     * 通过首字母查找省
     */
    private void check(String s1, String province) throws UiObjectNotFoundException {
        sleep(ChatClient.overtime_2);
        showMsg("===首字母查找====");
        int provincePosition = 0;//省的位置

        switch (s1) {
            case "A":
                mDevice.click(1010, 700);
                break;
            case "B":
                mDevice.click(1010, 760);
                break;
            case "C":
                mDevice.click(1010, 820);
                break;
            case "F":
                mDevice.click(1010, 870);
                break;
            case "G":
                mDevice.click(1010, 920);
                break;
            case "H":
                mDevice.click(1010, 960);
                break;
            case "J":
                mDevice.click(1010, 1020);
                break;
            case "L":
                mDevice.click(1010, 1070);
                break;
            case "N":
                mDevice.click(1010, 1120);
                break;
            case "Q":
                mDevice.click(1010, 1170);
                break;
            case "S":
                mDevice.click(1010, 1230);
                break;
            case "T":
                provincePosition = 1;
                mDevice.click(1010, 1270);
                break;
            case "X":
                provincePosition = 1;
                mDevice.click(1010, 1320);
                break;
            case "Y":
                provincePosition = 1;
                mDevice.click(1010, 1370);
                break;
            case "Z":
                provincePosition = 1;
                mDevice.click(1010, 1450);
                break;
        }
        sleep(3000);
        while (true) {
            UiObject list = mDevice.findObject(new UiSelector().className("android.widget.ListView").resourceId("com.chinamworld" +
                    ".main:id/cslhl_content"));
            /**
             * 适配金立
             */
            UiObject view = null;
            view = list.getChild(new UiSelector().className("android.view.ViewGroup").index(provincePosition));
            UiObject text = view.getChild(new UiSelector().className("android.widget.TextView").index(0));
            showMsg("===准备检测控件是否存在====" + provincePosition);
            if (text.exists()) {
                String s = text.getText();
                showMsg("===匹配字母====" + s);
                if (s.equals(s1)) {
                    showMsg("===首字母匹配到====" + s);
                    getProvince(province, provincePosition);
                    break;
                } else {
                    showMsg("===首字母未匹配到====" + s1);
                    provincePosition++;
                }
            }
        }
    }

    /**
     * 在某一字母下查找
     */
    private void getProvince(String province, int provincePosition) {
        try {
            int position = 0;
            sleep(ChatClient.overtime_2);
            showMsg("===准备具体查找====" + province);
            while (true) {
                UiObject list = mDevice.findObject(new UiSelector().className("android.widget.ListView").resourceId("com.chinamworld" +
                        ".main:id/cslhl_content"));
                /**
                 * 适配金立
                 */
                UiObject view = null;
                view = list.getChild(new UiSelector().className("android.view.ViewGroup").index(provincePosition));
                UiObject linearLayout = view.getChild(new UiSelector().className("android.widget.LinearLayout").index(1));
                UiObject text = linearLayout.getChild(new UiSelector().className("android.widget.TextView").index(position));
                showMsg("===遍历子选项====" + position);
                if (text.exists()) {
                    showMsg("====准备具体查找===listview====");
                    String s = text.getText();
                    showMsg("====准备具体查找====通过该内容进行匹配====" + s);
                    if (province.contains(s)) {
                        showMsg("====准备具体查找====内容匹配====" + s);
                        text.click();
                        break;
                    } else {
                        showMsg("====准备具体查找====内容不匹配====" + s);
                        position += 2;//每次递增2 是因为有分割线
                    }
                }
            }
        } catch (UiObjectNotFoundException e) {
            e.printStackTrace();
        }
    }

    /**
     * 图形验证码
     *
     * @throws UiObjectNotFoundException
     */
    public void BankPwd() throws UiObjectNotFoundException {
        UiObject et_code1 = mDevice.findObject(new UiSelector().resourceId("com.chinamworld.main:id/et_code"));
        et_code1.click();
        sleep(ChatClient.overtime_1);
        showMsg("输入取款密码");
        setClickN(user.getBankpwd());
        Constants.TV_TIPS = "";
        sleep(ChatClient.overtime_1);
        mDevice.click((int) (663 * ratio), (int) (816 * ratio));
        sleep(ChatClient.overtime_1);
        imageCode();
    }

    /**
     * 图形验证码
     *
     * @throws UiObjectNotFoundException
     */
    public void imageCode() throws UiObjectNotFoundException {
        long startTime = System.currentTimeMillis();
        while (true) {
            boolean isOutTime = CodeUtils.outTime(startTime, ChatClient.overtime_30, "imageCode超时...", isReport);
            if (isOutTime) {
                return;
            }
            sleep(ChatClient.overtime_1);
            try {
                showMsg("===imageCode====:");
                CODE_S = "";
                String code = ImageView.getImage("com.chinamworld.main:id/native_graph_iv", "中国建设银行");
                if (!code.equals("###")) {
                    UiObject et_code2 = mDevice.findObject(new UiSelector().resourceId("com.chinamworld.main:id/native_graph_et"));
                    et_code2.setText(code);
                    sleep(ChatClient.overtime_1);
                    showMsg("===code====:" + code);
                }
            } catch (Exception e) {
                setDevicesLog(e.toString());
                e.printStackTrace();
            } finally {
                ChatClient.vrifyCodeText = "";
            }
            sleep(ChatClient.overtime_1);
            //确定
            UiObject ok1 = mDevice.findObject(new UiSelector().resourceId("com.chinamworld.main:id/btn_confirm"));
            //如果确定按钮可用，点击，不可用重新填写验证码
            if (ok1.isEnabled()) {
                ok1.click();
                showMsg("----点击确定1---");
                break;
            } else {
                showMsg("----确认按钮不可用，重新请求验证码1---");
                UiObject image = mDevice.findObject(new UiSelector().resourceId("com.chinamworld.main:id/native_graph_iv"));
                image.click();
                sleep(ChatClient.overtime_4);
            }
        }
    }

    /**
     * 附加图形验证码
     *
     * @throws UiObjectNotFoundException
     */
    public void imageCode_f() throws UiObjectNotFoundException {
        long startTime = System.currentTimeMillis();
        while (true) {
            boolean isOutTime = CodeUtils.outTime(startTime, ChatClient.overtime_30, "验证码确定超时...", isReport);
            if (isOutTime) {
                return;
            }
            try {
                CODE_S = "";
                CODE_TIMER++;
                showMsg("=====重新获取附加码验证====第" + CODE_TIMER + "次重新获取附加码验证=====");
                addWorkTime(ChatClient.overtime_10);
                String code = ImageView.getImage("com.chinamworld.main:id/iv_addition_code", "中国建设银行");
                if (!code.equals("###")) {
                    UiObject et_code2 = mDevice.findObject(new UiSelector().resourceId("com.chinamworld.main:id/et_code"));
                    showMsg("----获取图片附加码信息---" + code);
                    et_code2.legacySetText("");
                    sleep(ChatClient.overtime_1);
                    et_code2.setText(code);
                    sleep(ChatClient.overtime_1);
                    mDevice.click(1000, 1400);
                    sleep(ChatClient.overtime_1);
                    showMsg("===code====:" + code);
                }

            } catch (UiObjectNotFoundException e) {
                showMsg("未找到控件异常:" + e.toString());
            } catch (Exception e) {
                setDevicesLog(e.toString());
                e.printStackTrace();
            } finally {
                ChatClient.vrifyCodeText = "";
            }

            sleep(2000);
            //确定
            UiObject ok1 = mDevice.findObject(new UiSelector().resourceId("com.chinamworld.main:id/btn_confirm"));
            //如果确定按钮可用，点击，不可用重新填写验证码
            if (ok1 != null && ok1.exists() && ok1.isEnabled()) {
                ok1.click();
                CODE_TIMER = 0;
                showMsg("----点击确定2---");
                break;
            } else {
                showMsg("----确认按钮不可用，重新请求验证码2---");
                UiObject image = mDevice.findObject(new UiSelector().resourceId("com.chinamworld.main:id/iv_addition_code"));
                image.click();
                sleep(ChatClient.overtime_2);
                mDevice.click(450, 1160);
                sleep(ChatClient.overtime_1);
            }
        }
    }

    /**
     * 完成转账后回复服务端
     *
     * @param sumMoney：余额
     * @throws Exception
     */
    public void getUserInfo(String sumMoney) {
        try {
            showMsg("===账户余额：====");
            String balance = "";
            String type = "";
            ChatClient.begintime = System.currentTimeMillis();//开始时间
            while (true) {
                boolean isOutTime = CodeUtils.outTime(ChatClient.begintime, ChatClient.overtime_60, "结果页超时...", isReport);
                if (isOutTime) {
                    return;
                }
                UiObject state = mDevice.findObject(new UiSelector().resourceId("com.chinamworld.main:id/title_success"));
                if (state.exists()) {
                    showMsg("===转账完成===");
                    type = state.getText();
                    if (Constants.getStr(type) == 0) {
                        DecimalFormat formater = new DecimalFormat("#0.##");
                        balance = formater.format(Double.parseDouble(sumMoney) - Double.parseDouble(list.get(0).getMoney()));
                        break;
                    } else {
                        balance = sumMoney;
                        break;
                    }
                }
            }
            ChatClient.reportTransferOrder(BANK_NAME, type, balance, Constants.getStr(type));
            sleep(ChatClient.overtime_1);
            showMsg("===准备检测转账完成=====");
            ChatClient.begintime = System.currentTimeMillis();//开始时间
            while (true) {
                boolean outTime = CodeUtils.outTime(ChatClient.begintime, ChatClient.overtime_30, "完成按钮超时...", Constants.isReport);
                if (outTime) {
                    return;
                }
                UiObject seven = mDevice.findObject(new UiSelector().text("完成").resourceId("com.chinamworld" +
                        ".main:id/ccb_title_right_btn"));
                showMsg("===检测转账完成=====");
                if (seven.exists()) {
                    showMsg("===点击转账完成=====");
                    seven.click();
                    break;
                }
            }
            sleep(ChatClient.overtime_3);
            ChatClient.begintime = System.currentTimeMillis();//开始时间
            while (true) {
                boolean outTime = CodeUtils.outTime(ChatClient.begintime, ChatClient.overtime_30, "返回转账页超时...", Constants.isReport);
                if (outTime) {
                    return;
                }
                UiObject function = mDevice.findObject(new UiSelector().text("转账").resourceId("com.chinamworld.main:id/tv_function"));
                if (function.exists()) {
                    mDevice.click((int) (87 * ratio), (int) (247 * ratio));
                    mDevice.click((int) (87 * ratio), (int) (247 * ratio));
                    showMsg("===转账完成进入转账页面=====");
                    break;
                }
            }
            sleep(ChatClient.overtime_2);
        } catch (Exception e) {
            setDevicesLog(e.toString());
            e.printStackTrace();
        }
    }

    /**
     * 获取余额
     */
    private void getBalance() throws UiObjectNotFoundException {
        sleep(ChatClient.overtime_5);
        ChatClient.begintime = System.currentTimeMillis();//开始时间
        while (true) {
            boolean outTime = CodeUtils.outTime(ChatClient.begintime, ChatClient.overtime_30, "金额获取超时...", Constants.isReport);
            if (outTime) {
                return;
            }
            UiObject zhuanzhang = CodeUtils.getUiObject_textOrId("转账金额", "com.chinamworld.main:id/sum_edittext_title");
            UiObject bank = CodeUtils.getUiObject_textOrId("选择付款账户", "com.chinamworld.main:id/title_cards_popwindow");
            if (zhuanzhang.exists()) {
                while (true) {
                    UiObject moeny = mDevice.findObject(new UiSelector().resourceId("com.chinamworld.main:id/tv_pay_info"));
                    if (moeny.exists()) {
                        showMsg("====获取金额显示====:" + moeny.getText());
                        if (moeny.getText().indexOf("-") == -1) {
                            String[] res = moeny.getText().split("  ");
                            sumMoney = res[2];
                            sumMoney = sumMoney.replaceAll(",", "");
                            C_updateBalance_W(Double.parseDouble(sumMoney));
                        }
                        break;
                    }
                }
                showMsg("==等待订单=moeny====:" + sumMoney);
                sleep(ChatClient.overtime_2);
                //返回
                back();
                showMsg("=====点击返回====");
                break;
            } else if (bank.exists()) {
                while (true) {
                    boolean outTime1 = CodeUtils.outTime(ChatClient.begintime, ChatClient.overtime_5, "完成按钮超时...", Constants.notReport);
                    if (outTime1) {
                        mDevice.click((int) (50 * ratio), (int) (1117 * ratio));
                        break;
                    }
                    UiObject selectb0 = mDevice.findObject(new UiSelector().resourceId("com.chinamworld.main:id/close_cards_popwindow"));
                    if (selectb0.exists()) {
                        selectb0.click();
                        break;
                    }
                }
            }
        }
    }

    /**
     * 查账
     *
     * @throws UiObjectNotFoundException
     */
    public void auditOrder() throws UiObjectNotFoundException {
        showMsg("===获取余额=====");
        getBalance();
        //进入转账记录
        ChatClient.begintime = System.currentTimeMillis();//开始时间
        while (true) {
            boolean outTime = CodeUtils.outTime(ChatClient.begintime, ChatClient.overtime_30, "点击查账按钮超时...", Constants.isReport);
            if (outTime) {
                return;
            }
            UiObject zhuanzhang = mDevice.findObject(new UiSelector().resourceId("com.chinamworld.main:id/layout_details").className
                    ("android.widget.LinearLayout"));
            if (zhuanzhang.exists()) {
                showMsg("===点击查账按钮===");
                zhuanzhang.click();
                break;
            }
        }
        //进入汇款记录明细
        ChatClient.begintime = System.currentTimeMillis();//开始时间
        while (true) {
            boolean outTime = CodeUtils.outTime(ChatClient.begintime, ChatClient.overtime_30, "转账记录超时...", Constants.isReport);
            if (outTime) {
                return;
            }
            UiObject next = CodeUtils.getUiObject_textOrId("转账记录", "com.chinamworld.main:id/ccb_title_text");
            if (next.exists()) {
                showMsg("===进入转账记录=====");
                break;
            }
        }
        //获取交易记录
        ChatClient.begintime = System.currentTimeMillis();//开始时间
        while (true) {
            boolean outTime = CodeUtils.outTime(ChatClient.begintime, ChatClient.overtime_30, "没有转账记录...", Constants.notReport);
            if (outTime) {
                showMsg("===没有该笔转账记录=====");
                ChatClient.reportAuditOrder("6", bank);
                break;
            }
            UiObject listView = mDevice.findObject(new UiSelector().resourceId("com.chinamworld.main:id/lv_transfer_record"));
            UiObject linearLayout0 = listView.getChild(new UiSelector().className("android.widget.LinearLayout").index(0));
            if (linearLayout0.exists()) {
                String username = CodeUtils.getUiObject_content(linearLayout0.getChild(new UiSelector().resourceId("com.chinamworld" +
                        ".main:id/tv_payee_accname")));
                String money = CodeUtils.getUiObject_content(linearLayout0.getChild(new UiSelector().resourceId("com.chinamworld" +
                        ".main:id/tv_amount")));
                String bankNo = CodeUtils.getUiObject_content(linearLayout0.getChild(new UiSelector().resourceId("com.chinamworld" +
                        ".main:id/tv_payee_accno")));
                showMsg("money:" + sumMoney);
                String bankNo0 = list.get(0).getBankNo().substring(list.get(0).getBankNo().length() - 4, list.get(0).getBankNo
                        ().length());
                String bankNo1 = bankNo.substring(bankNo.length() - 4, bankNo.length());
                String moery1 = money.replaceAll(",", "");
                showMsg("==订单金额是否相等==" + String.valueOf(Double.parseDouble(list.get(0).getMoney()) == Double.parseDouble(moery1)));
                showMsg("====转账目标名====" + String.valueOf(list.get(0).getUserName().equals(username)));
                showMsg("====转账卡号相等====" + String.valueOf(bankNo0.equals(bankNo1)));
                showMsg("====查到账单====" + username + "---" + moery1 + "---" + bankNo1);
                String state = "1";
                if (Double.parseDouble(list.get(0).getMoney()) == Double.parseDouble(moery1) && list.get(0).getUserName().equals(username) &&
                        bankNo0.equals(bankNo1)) {
                    state = "0";
                } else {
                    String sumMoneyFile = user.getUserName() + BANK_FLAG + "_sumMoney.txt";
                    String oldMoney = FileHelper.readSDFile(sumMoneyFile);
                    state = Constants.changeInAmount(BANK_FLAG, oldMoney, sumMoney, list.get(0).getMoney());
                }
                ChatClient.reportAuditOrder(state, bank);
                showMsg("===转账记录查询完成=====");
                break;
            }
        }
        ChatClient.begintime = System.currentTimeMillis();//开始时间
        while (true) {
            boolean outTime = CodeUtils.outTime(ChatClient.begintime, ChatClient.overtime_30, "返回上页超时...", Constants.isReport);
            if (outTime) {
                return;
            }
            UiObject back = mDevice.findObject(new UiSelector().resourceId("com.chinamworld.main:id/ccb_title_left_btn").className
                    ("android.widget.Button"));
            if (back.exists()) {
                showMsg("返回上页...");
                back.click();
                break;
            }
        }
        ChatClient.begintime = System.currentTimeMillis();//开始时间
        while (true) {
            boolean outTime = CodeUtils.outTime(ChatClient.begintime, ChatClient.overtime_30, "转账页超时...", Constants.isReport);
            if (outTime) {
                return;
            }
            UiObject zhuanzhang = mDevice.findObject(new UiSelector().text("转账").resourceId("com.chinamworld.main:id/ccb_title_text"));
            if (zhuanzhang.exists()) {
                mDevice.click(135, 400);
                break;
            }
        }
        showMsg("===转账记录返回转账页面=====");
    }

    /**
     * 等待订单
     */
    public void setTimerun() {
        try {
            CCBMethodName = "setTimerun";
            showMsg("===等待订单=====");
            sleep(ChatClient.overtime_5);
            ChatClient.begintime = System.currentTimeMillis();//开始时间
            while (true) {
                boolean outTime = CodeUtils.outTime(ChatClient.begintime, ChatClient.overtime_10, "没有转账按钮...", Constants.notReport);
                if (outTime) {
                    break;
                }
                UiObject remittance = CodeUtils.getUiObject_textOrId("转账", "com.chinamworld.main:id/tv_function");
                if (remittance.exists()) {
                    showMsg("=====选择转账按钮========");
                    remittance.click();
                    break;
                }
            }
            sleep(ChatClient.overtime_1);

            ChatClient.begintime = System.currentTimeMillis();//开始时间
            while (true) {
                boolean outTime = CodeUtils.outTime(ChatClient.begintime, ChatClient.overtime_5, "没有转账按钮...", Constants.notReport);
                if (outTime) {
                    break;
                }
                UiObject mLL_pay_card_info = mDevice.findObject(new UiSelector().resourceId("com.chinamworld.main:id/ll_pay_info"));
                if (mLL_pay_card_info.exists()) {
                    showMsg("点击银行卡...");
                    mLL_pay_card_info.click();
                    break;
                }
            }
            sleep(ChatClient.overtime_1);
            ChatClient.begintime = System.currentTimeMillis();//开始时间
            while (true) {
                boolean isOutTime = CodeUtils.outTime(ChatClient.begintime, ChatClient.overtime_5, "坐标选择转账银行卡...", Constants.notReport);
                if (isOutTime) {
                    mDevice.click(600, 320);
                    break;
                }
                UiObject mIV = mDevice.findObject(new UiSelector().resourceId("com.chinamworld.main:id/iv_card_selected"));
                if (mIV.exists()) {
                    showMsg("选择转账银行卡...");
                    mIV.click();
                    break;
                }
            }
            sleep(ChatClient.overtime_2);
            ChatClient.begintime = System.currentTimeMillis();//开始时间
            while (true) {
                boolean isOutTime = CodeUtils.outTime(ChatClient.begintime, ChatClient.overtime_60, "金额上报错误超时...", Constants.isReport);
                if (isOutTime) {
                    return;
                }
                UiObject zhuanzhang0 = mDevice.findObject(new UiSelector().resourceId("com.chinamworld.main:id/sum_edittext_title").text("转账金额"));
                UiObject bank0 = mDevice.findObject(new UiSelector().resourceId("com.chinamworld.main:id/title_cards_popwindow").text("选择付款账户"));
                if (zhuanzhang0.exists()) {
                    showMsg("=====存在转账金额======");
                    long begin_time = System.currentTimeMillis();//开始时间
                    while (true) {
                        boolean isOutTime1 = CodeUtils.outTime(begin_time, ChatClient.overtime_30, "获取金额超时...", Constants.notReport);
                        if (isOutTime1) {
                            break;
                        }
                        UiObject moeny = mDevice.findObject(new UiSelector().resourceId("com.chinamworld.main:id/tv_pay_info"));
                        if (moeny.exists()) {
                            showMsg("====获取金额显示====:" + moeny.getText());
                            if (moeny.getText().indexOf("-") == -1) {
                                String[] res = moeny.getText().split("  ");
                                sumMoney = res[2];
                                sumMoney = sumMoney.replaceAll(",", "");
                                C_updateBalance_W(Double.parseDouble(sumMoney));
                                showMsg("===本地保存余额===");
                                String sumMoneyFile = user.getUserName() + BANK_FLAG + "_sumMoney.txt";
                                FileHelper.saveMoneySDFile(false, sumMoney, sumMoneyFile);
                            }
                            break;
                        }
                    }
                    showMsg("===等待订单=moeny====:" + sumMoney);
                    sleep(ChatClient.overtime_1);
                    break;
                } else if (bank0.exists()) {
                    while (true) {
                        boolean isOutTime1 = CodeUtils.outTime(ChatClient.begintime, ChatClient.overtime_5, "坐标选择转账银行卡...", Constants.notReport);
                        if (isOutTime1) {
                            mDevice.click(75, 1850);
                            break;
                        }
                        UiObject selectb0 = mDevice.findObject(new UiSelector().resourceId("com.chinamworld.main:id/close_cards_popwindow"));
                        if (selectb0.exists()) {
                            showMsg("选择转账银行卡...");
                            selectb0.click();
                            break;
                        }
                    }
                }
            }
            Constants.CODE = "";
            ChatClient.waitExistOrder(ChatClient.overtime_60);
        } catch (Exception e) {
            setDevicesLog(e.toString());
            ChatClient.timer("setTimerun", ChatClient.error);
            e.printStackTrace();
        }
    }

    /**
     * 模拟点击密码
     *
     * @param pad_
     * @throws Exception
     */
    public void setClick(String pad_) {
        char[] abc = "1234567890qwertyuiopasdfghjklzxcvbnm".toCharArray();//char数组
        char[] pwd = pad_.toCharArray();//char数组
        for (int j = 0; j < pwd.length; j++) {
            for (int i = 0; i < abc.length; i++) {
                if (abc[i] == pwd[j]) {
                    mDevice.click((xy_abc[i][0]), (xy_abc[i][1]));
                    showMsg("====---点击字母====" + j);
                    sleep(ChatClient.overtime_1);
                    break;
                }
            }
        }
    }

    /**
     * 模拟点击自带键盘密码
     *
     * @param pad_
     * @throws Exception
     */
    public void setClickN(String pad_) {
        char[] abc = "123456789.0".toCharArray();//char数组
        char[] pwd = pad_.toCharArray();//char数组
        for (int j = 0; j < pwd.length; j++) {
            for (int i = 0; i < abc.length; i++) {
                if (abc[i] == pwd[j]) {
                    showMsg("点击+1");
                    mDevice.click(xy_num[i][0], xy_num[i][1]);
                    sleep(ChatClient.overtime_1);
                    break;
                }
            }
        }
    }


    /**
     * 模拟点击自带键盘密码
     *
     * @param pad_
     * @throws Exception
     */
    public void setClickXunFeiN(String pad_) {
        showMsg("验证码为====" + pad_);
        char[] abc = "1234567890".toCharArray();//char数组
        char[] pwd = pad_.toCharArray();//char数组
        for (int j = 0; j < pwd.length; j++) {
            for (int i = 0; i < abc.length; i++) {
                if (abc[i] == pwd[j]) {
                    mDevice.click((xy_num_xunfei[i][0]), (xy_num_xunfei[i][1]));
                    showMsg("点击数字====" + pwd[j] + "----" + xy_num_xunfei[i][0] + "，" + xy_num_xunfei[i][1]);
                    sleep(ChatClient.overtime_1);
                    break;
                }
            }
        }
    }

    /**
     * 字母和数字键盘的切换
     *
     * @param checkStr
     * @return
     */
    public boolean isNumeric(String checkStr) throws UiObjectNotFoundException {
        try {
            Integer.parseInt(checkStr);
            //切换数字键盘
            if (type.equals("abc")) {
                type = "123";
                while (true) {
                    UiObject num123 = mDevice.findObject(new UiSelector().resourceId("com.yitong.mbank.psbc:id/btnAbcBoardChangeNumber"));
                    if (num123.exists()) {
                        num123.click();
                        break;
                    }
                }
                sleep(ChatClient.overtime_1);
            }
            return true;
        } catch (NumberFormatException err) {
            //切换字母键盘
            if (!type.equals("abc")) {
                type = "abc";
                while (true) {
                    UiObject abc = mDevice.findObject(new UiSelector().resourceId("com.yitong.mbank.psbc:id/btnNumBoardChangeAbc"));
                    if (abc.exists()) {
                        abc.click();
                        break;
                    }
                }
                sleep(ChatClient.overtime_1);
            }
            return false;
        }
    }


    /**
     * 返回
     */
    public void back() throws UiObjectNotFoundException {
        ChatClient.begintime = System.currentTimeMillis();//开始时间
        while (true) {
            boolean isOutTime = CodeUtils.outTime(ChatClient.begintime, ChatClient.overtime_8, "返回...", Constants.notReport);
            if (isOutTime) {
                mDevice.pressBack();
                ChatClient.begintime = System.currentTimeMillis();
            }
            UiObject selectb0 = mDevice.findObject(new UiSelector().resourceId("com.chinamworld.main:id/close_cards_popwindow"));
            if (selectb0.exists()) {
                showMsg("====关闭选择账户弹窗====");
                selectb0.click();
            }
            UiObject mTV = mDevice.findObject(new UiSelector().resourceId("com.chinamworld.main:id/tv_function").text("预约转账"));
            if (mTV.exists()) {
                showMsg("====以返回转账首页====");
                return;
            }
        }
    }

    /**
     * 选择收款银行
     *
     * @throws UiObjectNotFoundException
     */
    public boolean addBank() throws UiObjectNotFoundException {
        showMsg("=====进入选择银行========");
        CCBMethodName = "addBank";
        //进入收款银行选择
        ChatClient.begintime = System.currentTimeMillis();//开始时间
        while (true) {
            boolean isOutTime = CodeUtils.outTime(ChatClient.begintime, ChatClient.overtime_5, "进入收款银行页超时...", Constants.isReport);
            if (isOutTime) {
                return false;
            }
            UiObject zhuanzhang = mDevice.findObject(new UiSelector().text("收款银行").resourceId("com.chinamworld.main:id/ctv_title"));
            //判断是否进入转账页面
            if (zhuanzhang.exists()) {
                sleep(ChatClient.overtime_1);
                break;
            }
        }
        String bankName = orderBankName;
        showMsg("=====转入银行========");
        //判断收款银行是否为建设银行
        if (bankName.indexOf("建设") != -1) {
            while (true) {
                UiObject bankName_search = mDevice.findObject(new UiSelector().resourceId("com.chinamworld.main:id/search_et"));
                if (bankName_search.exists()) {
                    sleep(ChatClient.overtime_1);
                    //点击热门的建设银行图标
                    showMsg("点击了同行转账========" + bankName);
                    mDevice.click(170, 560);
                    mDevice.click(170, 560);
                    break;
                }
            }
        } else {
            //获取收款银行控件
            ChatClient.begintime = System.currentTimeMillis();//开始时间
            while (true) {
                boolean isOutTime = CodeUtils.outTime(ChatClient.begintime, ChatClient.overtime_30, "搜索框超时...", Constants.isReport);
                if (isOutTime) {
                    return false;
                }
                UiObject bankName_search = mDevice.findObject(new UiSelector().resourceId("com.chinamworld.main:id/search_et"));
                if (bankName_search.exists()) {
                    sleep(ChatClient.overtime_1);
                    //获取收款银行控件
                    //检索收款银行
                    bankName_search.setText(orderBankName);
                    showMsg("检索银行========" + bankName);
                    break;
                }
            }

            //点击检索到银行
            ChatClient.begintime = System.currentTimeMillis();//开始时间
            while (true) {
                boolean isOutTime = CodeUtils.outTime(ChatClient.begintime, ChatClient.overtime_20, "收款银行名异常...", Constants.notReport);
                if (isOutTime) {
                    ChatClient.reportTransferOrder(BANK_NAME, "收款银行名异常", sumMoney, 1);
                    UiObject cib_close = mDevice.findObject(new UiSelector().resourceId("com.chinamworld.main:id/cib_close"));
                    if (cib_close.exists()) {
                        cib_close.click();
                    }
                    return false;
                }
                UiObject bankname0 = mDevice.findObject(new UiSelector().text(orderBankName).className("android.widget.TextView"));
                if (bankname0.exists()) {
                    showMsg("点击银行======" + bankName);
                    bankname0.click();
                    break;
                }
            }
        }
        return true;
    }

    /**
     * 获取短信序列号
     *
     * @throws UiObjectNotFoundException
     */
    public void getCodeType() throws UiObjectNotFoundException {
        showMsg("获取验证码序列号====");
        while (true) {
            UiObject text_code = CodeUtils.getUiObject_textOrId("重新获取", "com.chinamworld.main:id/re_send");
            UiObject text = mDevice.findObject(new UiSelector().resourceId("com.chinamworld.main:id/tv_tips"));
            if (text.exists() && !TextUtils.isEmpty(text.getText())) {
                Constants.TV_TIPS = text.getText();
                showMsg("===验证码序列号====" + Constants.TV_TIPS);
                break;
            } else if (text_code.exists()) {
                break;
            }
        }
    }

    /**
     * 发送限额信息
     */
    private void sendRePropcessInfo(String info) throws UiObjectNotFoundException {
        ChatClient.reportTransferOrder(BANK_NAME, info, sumMoney, 1);
        showMsg("===删除订单完成====");
        sleep(ChatClient.overtime_8);
        ChatClient.begintime = System.currentTimeMillis();//开始时间
        while (true) {
            boolean outTime = CodeUtils.outTime(ChatClient.begintime, ChatClient.overtime_10, "返回超时...", Constants.notReport);
            if (outTime) {
                break;
            }
            UiObject leftBack = mDevice.findObject(new UiSelector().className("android.widget.Button").resourceId("com.chinamworld" +
                    ".main:id/ccb_title_left_btn"));
            UiObject zhuanzhang = CodeUtils.getUiObject_textOrId("转账", "com.chinamworld.main:id/ccb_title_text");
            showMsg("===检测转账页面的返回键====");
            if (zhuanzhang.exists() || leftBack.exists()) {
                showMsg("===点击转账页面的返回键====");
                leftBack.click();
                break;
            }
        }

        ChatClient.begintime = System.currentTimeMillis();//开始时间
        while (true) {
            boolean outTime = CodeUtils.outTime(ChatClient.begintime, ChatClient.overtime_30, "预约转账超时...", Constants.isReport);
            if (outTime) {
                return;
            }
            UiObject zhuanzhang = CodeUtils.getUiObject_textOrId("预约转账", "com.chinamworld.main:id/tv_function");
            if (zhuanzhang.exists()) {
                showMsg("===转账完成进入转账页面=====");
                mDevice.click((int) (87 * ratio), (int) (247 * ratio));
                break;
            }
        }
    }


    /**
     * 发送未搜索到开户行信息
     */
    private void sendUnBankInfo(String info) {
        ChatClient.reportTransferOrder(BANK_NAME, info, sumMoney, 1);
        showMsg("===删除订单完成====");
    }

    public void showMsg(String msg) {
        LogToFile.showLog("建设银行", msg);
    }
}
